<?php


namespace App\Services\Questions;

use App\Models\Question;
use Illuminate\Http\Request;

abstract class BaseQuestion implements QuestionInterface
{
    /**
     * 添加的方法
     *
     * @param Request $request
     */
    public function store(Request $request)
    {
        // 增加需要的字段
        $request->offsetSet('user_id', auth('api')->id());

        // 移出html标签
        $title = strip_tags($request->input('content'));
        // 添加必要的字段
        $request->offsetSet('title', substr(trim($title),0,254));

        Question::create($request->all());
    }

    /**
     * 修改的方法
     *
     * @param Request $request
     * @param Question $question
     */
    public function update(Request $request, Question $question)
    {
        // 移出html标签
        $title = strip_tags($request->input('content'));
        // 添加必要的字段
        $request->offsetSet('title', substr(trim($title),0,254));

        $question->update($request->all());
    }
}
